package net.j4love.protobuf.service;

import com.google.protobuf.Descriptors;
import com.google.protobuf.Message;
import com.google.protobuf.RpcController;
import com.google.protobuf.Service;
import org.junit.Test;

import static net.j4love.protobuf.ProtobufCompilerUtils.generateJavaCode;
import static net.j4love.protobuf.LocalEnvConfiguration.*;

/**
 * @author He Peng
 * @create 2018-05-12 23:54
 * @update 2018-05-12 23:54
 * @updatedesc : 更新说明
 * @see
 */


public class ProtobufGenerateServiceTest {

    @Test
    public void serviceCodeGenerateTest() throws Exception {
        String protobufFilePath = CODE_ABSOLUTE_PATH + "/src/main/java/net/j4love/protobuf/proto/time_service.proto";
        generateJavaCode(PROTOBUF_COMPILER_ABSOLUTE_PATH ,
                PROTO_PATH , CODE_PATH , protobufFilePath);
    }

    @Test
    public void serviceCallTest() throws Exception {
        Service timeService = TimeServiceWrapper.TimeService.newReflectiveService(new TimeServiceImpl());
        Descriptors.MethodDescriptor methodDescriptor = TimeServiceWrapper.TimeService.getDescriptor().findMethodByName("Time");
        RpcController controller = null;
        Message request = null;
        timeService.callMethod(methodDescriptor , controller , request ,
                parameter -> System.out.println("Called Service Callback : " + parameter));
    }

}
